﻿using CurrencyReferenceDAL;
using System.Windows;

namespace CurrencyReference
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var cm = new CurrencyManager(@"C:\Development\Trainings\WPF_Sept2015\CurrencyReference\eurofxref-daily.xml");
            DataContext = cm;
        }

        private void Calculate(object sender, RoutedEventArgs e)
        {
            double dblVal;
            if (double.TryParse(txtAmount.Text, out dblVal))
            {
                txtResult.Text = string.Format("{0:#,##0.00}", 
                                                dblVal / ((Currency)cbxCurrency.SelectedItem).RateAgainstEuro * ((rbEuro.IsChecked ?? false) ? 1 : 1.95583)
                                              )
                  ;
            }
        }
    }
}